package com.ruoyi.system.outto.game.impl;

// 1、这里只是以ocr下的RecognizeBankCard能力为例，其他能力请引入相应类目的包和相关类
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.ocr20191230.models.RecognizeBankCardResponse;
import com.aliyun.ocr20191230.models.RecognizeCharacterResponse;
import com.aliyun.ocr_api20210707.models.RecognizeGeneralResponse;
import com.aliyun.ocr_api20210707.models.RecognizeGeneralResponseBody;
import com.aliyun.tea.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class Sample {

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.ocr_api20210707.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 您的 AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的 AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";
        return new com.aliyun.ocr_api20210707.Client(config);
    }
///        LTAI4Fz5S8QLbyB92ZeyHFwz
//                kAzZh0hbiX2hNxpF8ZqD6hDyNzb0uv


    public static String parseText(String accessKeyId, String accessKeySecret,String path) throws Exception {


        com.aliyun.ocr_api20210707.Client client = Sample.createClient("LTAI4Fz5S8QLbyB92ZeyHFwz", "kAzZh0hbiX2hNxpF8ZqD6hDyNzb0uv");
        com.aliyun.ocr_api20210707.models.RecognizeGeneralRequest recognizeGeneralRequest = new com.aliyun.ocr_api20210707.models.RecognizeGeneralRequest();
        recognizeGeneralRequest.setUrl(path);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            RecognizeGeneralResponse recognizeGeneralResponse = client.recognizeGeneralWithOptions(recognizeGeneralRequest, runtime);
            RecognizeGeneralResponseBody body = recognizeGeneralResponse.getBody();
            String data = body.getData();
            JSONObject jsonObject = JSONObject.parseObject(data);
            return jsonObject.getString("content");
        } catch (TeaException error) {
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
        return null;
    }

}
                    